package com.mall.util.tree.rb;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * 红黑树结点属性
 */
@Data
@Accessors(chain = true)
public class RBNode<K extends Comparable<K>, V> {
    @Schema(description = "父结点")
    private RBNode parent;

    @Schema(description = "左结点")
    private RBNode left;

    @Schema(description = "右结点")
    private RBNode right;

    @Schema(description = "结点颜色")
    private RBColor color;

    @Schema(description = "结点索引")
    private K key;

    @Schema(description = "结点值")
    private V value;

    public RBNode(K key, V value) {
        this.key = key;
        this.value = value;

        /* 为了尽量保持树平衡，插入进来的结点要求是红色 */
        this.color = RBColor.RED;
    }

    @Override
    public String toString(){
        return value.toString();
    }
}
